package com.wteam.clightmini.serviceImpl;

import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.map.MapUtil;
import cn.hutool.http.HttpStatus;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wteam.clightmini.pojo.Menu;
import com.wteam.clightmini.mapper.MenuMapper;
import com.wteam.clightmini.service.MenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wteam.system.common.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 许则丕
 * @since 2022-07-12
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public ResultMessage add(Menu menu) {
        ResultMessage resultMessage = new ResultMessage();
        menuMapper.insert(menu);
        resultMessage.setStatus(HttpStatus.HTTP_OK);
        resultMessage.setMessage("新增成功");
        return resultMessage;
    }

    @Override
    public ResultMessage edit(Menu menu) {
        ResultMessage resultMessage = new ResultMessage();
        menuMapper.updateById(menu);
        resultMessage.setStatus(HttpStatus.HTTP_OK);
        resultMessage.setMessage("编辑成功");
        return resultMessage;
    }

    @Override
    public ResultMessage deleteMenu(Long id) {
        ResultMessage resultMessage = new ResultMessage();
        menuMapper.deleteById(id);
        resultMessage.setStatus(HttpStatus.HTTP_OK);
        resultMessage.setMessage("删除成功");
        return resultMessage;
    }

    @Override
    public ResultMessage hiddenMenu(Long id) {
        ResultMessage resultMessage = new ResultMessage();
        Menu menu = new Menu();
        menu.setId(id);
        menu.setIsHidden(true);
        menuMapper.updateById(menu);
        resultMessage.setStatus(HttpStatus.HTTP_OK);
        resultMessage.setMessage("隐藏成功");
        return resultMessage;
    }

    @Override
    public List<Menu> listMenu() {
        return menuMapper.selectList(null);
    }
}
